package k.web.cityManage;

import k.HelperClazz;
import k.dao.base.BaseDao;
import k.dao.base.EmpDao;
import k.dao.base.OrgDao;
import k.dto.Emp;
import k.service.EventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Created by sure on 2018/4/12.
 */
@Controller
@RequestMapping(value = "/sys")
public class SysController {
    @Autowired
    EmpDao empDao;
    @Autowired
    OrgDao orgDao;
    @Autowired
    private EventService eventService;

    //首页跳转
    @RequestMapping(value = "/index")
    public String index(Model model, HttpServletRequest request) {
        model.addAttribute("emp_id", HelperClazz.getEMP().getEmp_id());
        model.addAttribute("emp_name", HelperClazz.getEMP().getEmp_name());
        model.addAttribute("GroupList", eventService.findGroupList(HelperClazz.getEMP()));
        model.addAttribute("taskList", eventService.findTaskListByEmpId(HelperClazz.getEMP().getEmp_id().toString()));
        return "index";
    }
    //Grid
    @RequestMapping(value = "/grid")
    public String grid(Model model, HttpServletRequest request) {
        model.addAttribute("emp_id", HelperClazz.getEMP().getEmp_id());
        model.addAttribute("emp_name", HelperClazz.getEMP().getEmp_name());
        orgDao.findAll();
        model.addAttribute("org_ids", orgDao.findAll());
        return "system_manage/grid";
    }

    @RequestMapping(value = "/queryGridLocation")
    public String queryGridLocation(Model model, HttpServletRequest request) {
        model.addAttribute("emp_id", HelperClazz.getEMP().getEmp_id());
        model.addAttribute("emp_name", HelperClazz.getEMP().getEmp_name());
        return "system_manage/grid";
    }
    @RequestMapping(value = "/login")
    public String login(Model model, HttpServletRequest request) throws ServletException, IOException {
        String msg = request.getParameter("msg");
        String loginName = request.getParameter("loginName");
        String loginPwdSrc = request.getParameter("loginPwd");
        Emp emp = empDao.getEmp(loginName,loginPwdSrc);
        if (emp==null){
            return "index";
        }
        HelperClazz.setEMP(emp);
        model.addAttribute("emp_id", emp.getEmp_id());
        model.addAttribute("emp_name", emp.getEmp_name());
        model.addAttribute("GroupList", eventService.findGroupList(HelperClazz.getEMP()));
        model.addAttribute("taskList", eventService.findTaskListByEmpId(HelperClazz.getEMP().getEmp_id().toString()));
        return "index";//跳转到流程的主页
    }


}
